﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace UI
{
    public class UIContainer : UIElement
    {
        private List<UIElement> _elements = new List<UIElement>();

        private HashSet<UIElement> _has = new HashSet<UIElement>();

        internal void AddElement(UIElement ui)
        {
            if (_has.Contains(ui)) return;
            _has.Add(ui);
            _elements.Add(ui);
        }

        internal void RemoveElement(UIElement ui)
        {
            if (!_has.Contains(ui)) return;
            _has.Remove(ui);
            _elements.Remove(ui);
        }

        int Count { get { return _elements.Count; } }

        public UIElement this[string uiName]
        {
            get { return Find(uiName); }
        }

        public UIElement this[int index]
        {
            get { return Get(index); }
        }

        public UIElement Find(string uiName)
        {
            return _elements.Find((ui) => ui.name == uiName);
        }

        public UIElement Get(int index)
        {
            return _elements[index];
        }
    }


}
